#!/bin/sh
# postinst framework for openpanel packages
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

case "$1" in
    configure)
ln -sf /var/opencore/bin/opencore.app/exec /var/opencore/bin/opencore
# It's already created in openpanel-authd package, so just commenting
# ln -s /var/opencore/log /var/log/opencore
grep -q opencore /etc/group || groupadd -f opencore > /dev/null
grep -q opencore /etc/passwd || useradd opencore -r -g opencore > /dev/null
grep -q paneluser /etc/group || groupadd -f openadmin
grep -q openadmin /etc/passwd || useradd -m -G paneluser openadmin
update-rc.d openpanel-core start 94 2 3 4 5 . stop 74 0 1 6 . > /dev/null
chown opencore:opencore /var/opencore/cache
chmod 750 /var/opencore/cache
if [ ! -f /var/opencore/db/panel/panel.db ]; then
        cp /var/opencore/db/panel/panel.db.setup /var/opencore/db/panel/panel.db
fi
chown -R opencore:opencore /var/opencore/db
chmod 700 /var/opencore/db
chown -R opencore:opencore /var/opencore/debug
chmod -R 750 /var/opencore/debug
chown opencore:opencore /var/opencore/log
chmod 750 /var/opencore/log
chown -R opencore:authd /var/opencore/sockets
chmod 750 /var/opencore/conf/rollback
chown opencore:opencore /var/opencore/conf/rollback
chown root:opencore /var/opencore/conf/staging
chmod 770 /var/opencore/conf/staging

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


